package com.carkeeper.controller;

import com.carkeeper.dto.DepartmentDTO;
import com.carkeeper.dto.EmployeeDTO;
import com.carkeeper.dto.ServiceSubtypeDTO;
import com.carkeeper.pojo.EmployeePO;
import com.carkeeper.service.DepartmentService;
import com.carkeeper.service.EmployeeService;
import com.carkeeper.service.ServiceSubtypeFeign;
import com.carkeeper.vo.DepartmentVO;
import com.carkeeper.vo.EmployeeSimpleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/simple")
public class SimpleController {
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private ServiceSubtypeFeign serviceSubtypeFeign;

    /**
     * 获取部门简单列表
     *
     * @return 部门简单列表
     */
    @GetMapping("/department")
    public List<DepartmentDTO> simpleDepartments() {
        return departmentService.findAll(null);
    }

    /**
     * 获取简单运营后台员工列表
     *
     * @param hasUsername 是否分配了账号
     * @return 简单运营后台员工列表
     */
    @GetMapping("/employee")
    public List<EmployeeSimpleVO> simpleEmployees(@RequestParam(name = "hasUsername", required = false) Boolean hasUsername) {
        EmployeeDTO dto = new EmployeeDTO();
        dto.setHasUsername(hasUsername);
        List<EmployeePO> poList = employeeService.list(dto);
        return poList.stream().map(po -> {
            EmployeeSimpleVO vo = new EmployeeSimpleVO();
            vo.setId(po.getId());
            vo.setName(po.getName());
            return vo;
        }).collect(Collectors.toList());
    }

    /**
     * 获取简单服务二级分类列表
     *
     * @return 简单二级服务分类列表
     */
    @GetMapping("/serviceSubType")
    public List<ServiceSubtypeDTO> simpleServiceSubtypes() {
        return serviceSubtypeFeign.findAll();
    }
}
